package com.framework.service.yhbservice.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.YHBDao.indexDao.YhbIndexDao;
import com.framework.service.yhbservice.YhbIndexMenuService;
import com.framework.service.yhbservice.YhbIndexService;
import com.framework.service.yhbservice.YhbNoticeService;
import com.framework.service.yhbservice.YhbUserService;
import com.framework.yhbEntity.Index.YhbIndex;
import com.framework.yhbEntity.Index.YhbIndexMenu;
import com.framework.yhbEntity.notice.YhbNotice;
import com.framework.yhbEntity.user.YhbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Transactional(rollbackFor = Exception.class)
@Service("yhbIndexService")
public class YhbIndexServiceImpl extends ServiceImpl<YhbIndexDao,YhbIndex> implements YhbIndexService {

    @Autowired
    private YhbUserService yhbUserService;

    @Autowired
    private YhbIndexMenuService yhbIndexMenuService;

    @Autowired
    private YhbNoticeService yhbNoticeService;

    @Override
    public List<YhbIndex> getIndexBanner(String token, String type) {
        YhbUser user = yhbUserService.queryUserByToken(token);
        List<String> strings = new ArrayList<>();
        strings.add("sort");
        List<YhbIndex> list = baseMapper.selectList(new EntityWrapper<YhbIndex>()
                    .eq("dept_id",user.getDeptId())
                    .eq("state",1)
                    .eq("type",type)
                    .orderAsc(strings)
        );
        return list;
    }

    @Override
    public Map<String, Object> queryIndexInfo(String token) {
        List<YhbIndex> bannerlist = getIndexBanner(token, "1");
        List<YhbIndexMenu> menulist = yhbIndexMenuService.getIndexMenu(token);
        List<YhbNotice> noticlist = yhbNoticeService.getIndexNotice(token);
        Map<String,Object> map=new HashMap<>();
        map.put("bannerlist",bannerlist);
        map.put("menulist",menulist);
        map.put("noticlist",noticlist);
        return map;
    }

    @Override
    public YhbIndex queryBannerInfoById(Long id) {
        return baseMapper.selectById(id);
    }
}
